home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1991 …esperately Seeking Seven / Desperately Seeking Seven.2mg / Dev.CD.8 / Essentials / Tools / File.Type.Notes / FTN.E0.0002.3 < prev    next >
Encoding:
Text File  |  1990-12-11  |  21.9 KB  |  437 lines  |  [04] ASCII Text (0x0000)

  1. Apple II
  2. File Type Notes
  3. _____________________________________________________________________________
  4.                                                   Developer Technical Support
  5.  
  6. File Type:         $E0 (224)
  7. Auxiliary Types:   $0002 & $0003
  8.  
  9. Full Name:     AppleDouble Header File (Auxiliary Type $0002)
  10.                AppleDouble Data File (Auxiliary Type $0003)
  11. Short Name:    AppleDouble Header (Auxiliary Type $0002)
  12.                AppleDouble Data (Auxiliary Type $0003)
  13.  
  14. Revised by:    Matt Deatherage                                  November 1990
  15. Written by:    Matt Deatherage                                     March 1989
  16.  
  17. Files of these types and auxiliary types contain file data in AppleDouble
  18. format.
  19. Changes since March 1990:  Added information about AppleDouble 2.0.
  20. _____________________________________________________________________________
  21.  
  22. AppleDouble is one of two standards (the other is AppleSingle) put forth by
  23. Apple Computer, Inc. for representing files on foreign file systems while
  24. preserving all attributes of the file's home system on file systems that do not
  25. support the same attributes.
  26.  
  27. Experience indicated that a single format would be inadequate to cover all
  28. cases.  Two closely related formats, however, can serve most needs.  Although
  29. the primary impetus for developing these formats is storing extended files
  30. (files with both resource and data forks) on file systems that do not support
  31. the notion of two forks, the proposed formats are general enough that theycan be
  32. used to represent a file from any file system on any other file system.
  33.  
  34. AppleDouble keeps the data fork as a separate file from the file attributes and
  35. the resource fork, and this Note describes this file format.  AppleSingle keeps
  36. all attributes and the contents of both forks in a single file in the foreign
  37. file system, and is described in the File Type Note for File Type$E0, Auxiliary
  38. Type $0001.
  39.  
  40. AppleSingle is intended to be used primarily as a storage format, especially for
  41. cases where you must store an extended file on a foreign file system and later
  42. reconstruct the extended file.  AppleDouble is more appropriate for applications
  43. where the users of the foreign file system might want to modify the contents of
  44. the file.  Since most applications keep file data in the data fork, AppleDouble
  45. format saves the contents of the data fork in one file.All other file
  46. attributes, including the resource fork, are kept in a separate file.
  47.  
  48.  
  49. Reasons for Using AppleDouble
  50.  
  51. There are several reasons for supporting an interchange format between file
  52. systems.  Perhaps the most germane is one of the least obvious:  handling
  53. extended files on foreign file systems which do not support extended files.
  54.  
  55. For example, the ProDOS FST in GS/OS can create an extended file on a ProDOS
  56. disk.  However, ProDOS 8 is unable to operate on the file, since it sees itas
  57. having an unsupported storage type.  If a telecommunications program or other
  58. utility capable of transferring files is operating under ProDOS 8 andattempts to
  59. receive an extended file, it is unable to create the file.
  60.  
  61. At this point, the application could use READ_BLOCK and WRITE_BLOCK commands,
  62. along with a knowledge of the ProDOS file system, to create the file on its own.
  63. However, this is strongly discouraged.  The ProDOS file system format for
  64. extended files is not documented and could change in the future.  In addition,
  65. the program could be running on a eight-bit system.  If the disk is only used on
  66. an eight-bit system, the extended files would not only be unwanted, but also
  67. unremovable without using the disk on an Apple IIGS or later system running
  68. GS/OS.
  69.  
  70. However, if the application is aware of the AppleDouble format, it canquickly
  71. store an extended file in AppleDouble, leaving the conversion back to the
  72. extended file to GS/OS, or another operating system.  This is the recommended
  73. way for ProDOS 8 applications to create and handle extended files.  Useeither
  74. AppleSingle or AppleDouble.
  75.  
  76.  
  77. AppleDouble Format
  78.  
  79. AppleDouble consists of two files, an AppleDouble Header File and an AppleDouble
  80. Data File.  The AppleDouble Header file contains a headerfollowed by data.  The
  81. header consists of several fixed fields and a list of entry descriptors, each
  82. pointing to an entry.  Apple defines these standardentries: Resource Fork, Real
  83. Name (name in the home file system), Comment, Icon and File Info.  Each entry is
  84. optional, so it may not appear in the file.  Wealso define the new entry Data
  85. Pathname, pointing to the pathname of the AppleDouble Data File.  The Header
  86. File has exactly the same format as an AppleSingle file, except it has no data
  87. fork entry.  The AppleDouble DataFile consists of just the data fork of the
  88. file, with no extra header at all.
  89.  
  90. Note:  All numeric entries, including entries representing ProDOS data
  91.        structures (such as file type and auxiliary type) are Reverse
  92.        ordered.  This is provided so any host CPU can attempt to
  93.        interpret entries in the header without having to know the
  94.        standard byte-ordering of the home file system.  Therefore, in
  95.        this Note you see descriptive entries like "Rev. 4 Bytes."  This
  96.        serves as a reminder that all header fields are stored high byte
  97.        first, even though the notation Bytes does not imply any specific
  98.        ordering in other File Type Notes.
  99.  
  100. Also note that ASCII strings are not stored in reverse order, just non-ASCII
  101. constants.
  102.  
  103. The Header in the Header File:
  104.  
  105. Magic Number         Rev. Long    The Magic Number field is modeled after
  106.                                   the feature in UNIX.  It is intended to be
  107.                                   used in whatever way the foreign file
  108.                                   system distinguishes a file as AppleDouble
  109.                                   format.  See the section "Identifying
  110.                                   AppleDouble Files."  The Magic Number for
  111.                                   AppleDouble format is $00051607, which is
  112.                                   stored reverse as $00 $05 $16 $07 (reverse
  113.                                   of normal 65816/6502 order).
  114. Version Number       Rev. Long    The version of AppleDouble format, in case
  115.                                   the format evolves (more fields may be
  116.                                   added to the header).  The version
  117.                                   described here is $00010000, stored
  118.                                   (reverse) as $00 $01 $00 $00.
  119.  
  120. Home File System     16 Bytes     A fixed-length, 16-byte ASCII string not
  121.                                   preceded by a length byte, but possibly
  122.                                   padded with blanks.  Apple has defined
  123.                                   these values:
  124.                                   ProDOS    $50726F444F5320202020202020202020
  125.                                   Macintosh $4D6163696E746F736820202020202020
  126.                                   MS-DOS    $4D532D444F5320202020202020202020
  127.                                   Unix      $556E9878202020202020202020202020
  128.                                   VAX VMS   $56415820564D53202020202020202020
  129.                                   Apple welcomes suggestions for other file
  130.                                   systems that should be included in this
  131.                                   list.
  132. Number of entries    Rev. Word    Tells how many different entries are
  133.                                   included in the file.  This unsigned
  134.                                   reverse word may be zero.  If it is non-
  135.                                   zero, then that number of entry
  136.                                   descriptors immediately follows this
  137.                                   field.
  138.  
  139.  
  140. For Each Entry:
  141.  
  142. Entry ID             Rev. Long    Identifies the entry.  Apple has defined
  143.                                   the following Entry IDs and their values:
  144.                                   1 = Data Fork
  145.                                   2 = Resource Fork
  146.                                   3 = Real Name (The file's name in the home
  147.                                       file system)
  148.                                   4 = Comment* (standard Macintosh comment)
  149.                                   5 = Icon, B&W* (standard Macintosh black
  150.                                       and white icon)
  151.                                   6 = Icon, Color* (reserved for Macintosh
  152.                                       color icon)
  153.                                   7 = File Info (file attributes,dates, etc.)
  154.                                   9 = Finder Info* (standard Macintosh
  155.                                       Finder Info)
  156.                                   Entry IDs marked with asterisks (*) are
  157.                                   not used for most files created under
  158.                                   ProDOS or GS/OS.  Furthermore, icon
  159.                                   entries probably do not appear in most
  160.                                   files since they are typically stored as a
  161.                                   bundle in the application file's resource
  162.                                   fork on the Macintosh.  Apple reserves the
  163.                                   range of Entry IDs from $0 to $7FFFFFFF
  164.                                   for future use.  The rest of the range is
  165.                                   available for other systems to define
  166.                                   their own entries.  Apple does not
  167.                                   arbitrate the use of the rest of the
  168.                                   range.
  169.                                   Descriptions of the standard entries are
  170.                                   given below.
  171. Offset               Rev. Long    An unsigned reverse long which indicates
  172.                                   the byte offset from the start of the file
  173.                                   to the start of the entry.
  174. Entry Length         Rev. Long    An unsigned reverse long which indicates
  175.                                   the length of the entry in bytes.  The
  176.                                   length may be zero.
  177.  
  178.  
  179. Standard Entries:
  180.  
  181. The Real Name Entry:
  182.  
  183. The Real Name entry indicates the file's original filename in the host file
  184. system.  This is not a Pascal or C string; it is just ASCII data.  The length is
  185. indicated by the Entry Length field for the Real Name entry.
  186.  
  187. The File Info Entry:
  188.  
  189. The File Info entry (Entry ID = 7) is different for each home file system. For
  190. ProDOS files, the entry is 16 bytes long and consists of the creationdate and
  191. time and the modification date and time in ProDOS 8 (ProDOS 16/class zero GS/OS)
  192. form, the access word, a two-byte file type and four-byte auxiliary type.  This
  193. is detailed in standard format below, along with defined FileInfo entries for
  194. some other file systems.
  195.  
  196. ProDOS:
  197.  
  198. Create Date         Rev. 2 Bytes  Creation date packed into standard
  199.                                   ProDOS 8 format.
  200. Create Time         Rev. 2 Bytes  Creation time packed into standard
  201.                                   ProDOS 8 format.
  202. Modification Date   Rev. 2 Bytes  Modification date packed into
  203.                                   standard ProDOS 8 format.
  204. Modification Time   Rev. 2 Bytes  Modification time packed into
  205.                                   standard ProDOS 8 format.
  206. Access              Rev. Word     The file's access.  This may be used
  207.                                   directly in ProDOS 16 or GS/OS calls; only
  208.                                   the low byte is significant to ProDOS 8.
  209. File Type           Rev. Word     The file type of the original file.  Only
  210.                                   the low byte is significant to ProDOS 8.
  211. Auxiliary Type      Rev. Long     The auxiliary type of the original file.
  212.                                   Only the low word is significant to ProDOS
  213.                                   8.
  214.  
  215. Note:  Although the ProDOS Access field, File Type and Auxiliary Type are
  216.        the same length as found in ProDOS 16 and GS/OS structures, the
  217.        Create and Modification Dates and Times are stored in two-byte
  218.        (albeit byte-reversed) ProDOS 8 format, not eight-byte Apple IIGS
  219.        format.
  220.  
  221. Macintosh:
  222.  
  223. Create Date         Rev. Long     Unsigned number of seconds between
  224.                                   January 1, 1904, and the creation time of
  225.                                   this file.
  226. Modification Date   Rev. Long     Unsigned number of seconds between
  227.                                   January 1, 1904, and the last modification
  228.                                   of this file.
  229. Last Backup Date    Rev. Long     Unsigned number of seconds between
  230.                                   January 1, 1904, and the last backup time
  231.                                   of this file.
  232. Attributes          Rev. Long     32 boolean flags.  Once the bytes are
  233.                                   unreversed, bit zero is the locked bit and
  234.                                   bit one is the protected bit.
  235.  
  236. MS-DOS:
  237.  
  238. Modification Date    Rev. 4 Bytes  MS-DOS format modification date.
  239. Attributes           Rev. 2 Bytes  MS-DOS attributes.
  240.  
  241. Unix:
  242.  
  243. Create Date/Time       Rev. 4 Bytes  Unix creation date and time.
  244. Last Use Date/Time     Rev. 4 Bytes  Unix time for the last
  245.                                      time this file was used.
  246. Last Mod. Date/Time    Rev. 4 Bytes  Unix time for the last
  247.                                      time this file was modified.
  248.  
  249.  
  250. The Finder Info Entry:
  251.  
  252. The Finder Info entry (Entry ID = 9) is for files where the host file system is
  253. Macintosh.  It consists of 16 bytes of Finder Info followed by 16 bytes of
  254. Extended Finder Info.  These are the fields ioFlFndrInfo followed by
  255. ioFlXFndrInfo, as described in Inside Macintosh, Volume IV-183.  Newlycreated
  256. files have zeroes in all Finder Info subfields.  If you are creating an
  257. AppleDouble file whose home system is Macintosh, you may zero all unknown
  258. fields, but you may want to set the fdType and fdCreator subfields.
  259.  
  260.  
  261. The Data Pathname Entry:
  262.  
  263. The Data Pathname entry (Entry ID = 100) is defined for the first time inthis
  264. Note.  It consists of a class one GS/OS input string noting the pathname of the
  265. AppleDouble Data File as originally created:
  266.  
  267. Path Length    Rev. Word    The length of the pathname.
  268. Pathname       Bytes        ASCII pathname of the AppleDouble Data File
  269. when created.
  270.  
  271.  For strategies on using this segment (or not using it) to find theAppleDouble
  272. Data File, see the section "Finding the AppleDouble Data File."
  273.  
  274.  
  275. The Entries in the Header File:
  276.  
  277. The entries themselves follow the header field and the entry descriptors.The
  278. actual data representing each entry must be in a single, contiguous block. The
  279. offset field in that entry's descriptor points to it.  The entries could appear
  280. in any order, but since the data fork is the entry that is most commonly
  281. extended, Apple strongly recommends that the data fork always bekept last in the
  282. file to facilitate its extension.  Apple also recommends that those entries that
  283. are most often read, such as Real Name, File Info (and Finder Info if present)
  284. be kept as close as possible to the header tomaximize the probability that a
  285. read of the first few blocks of the file retrieves these entries.
  286.  
  287. It is possible to have holes in the file (unused space between entries).  To
  288. find the holes, you must take the list of entry descriptors and sort theminto
  289. increasing offset order.  If the offset field of an entry is greater than the
  290. offset plus the length of the previous entry (sorted), then a hole exists
  291. between the entries.  You can make use of such holes; for example, if afile's
  292. comment is ten bytes long, you could create a hole of 190 bytes after the
  293. comment field to easily allow for the comment to later expand to its maximum
  294. length of 200 bytes.  Because an AppleDouble file may contain holes, you must
  295. find each entry by getting its offset from its entry descriptor, not by assuming
  296. that it begins after the previous entry.
  297.  
  298. Byte ordering in file header fields follows 68000 convention, and each header
  299. field has been so noted by the Reverse operator.
  300.  
  301.  
  302. The AppleDouble Data File
  303.  
  304. The AppleDouble Data File is simply the data fork of the original file contained
  305. in a file of its own.  You may create it with a File Type and Auxiliary Type
  306. assignment best suited to it, if desired.  For example, if the program creating
  307. the AppleDouble Data File knows that the data fork contains strictly ASCII text,
  308. it could create the file with File Type $04 (Text File) so that other
  309. applications can deal with it accordingly.
  310.  
  311. If the creating program wishes to make no assumptions about the content ofthe
  312. data fork, it is encouraged to create the AppleDouble Data File with filetype
  313. $E0 and auxiliary type $0003.  This identifies the file as an AppleDoubleData
  314. File.
  315.  
  316.  
  317. Identifying AppleDouble Files
  318.  
  319. As this is an interchange format, from a ProDOS directory entry there is no way
  320. to guarantee which files are AppleDouble files.  Apple has allocated File Type
  321. $E0, Auxiliary Type $0002 for files which are AppleDouble Header Files, and File
  322. Type $E0, Auxiliary Type $0003 for files which are AppleDouble Data Files.  We
  323. strongly encourage ProDOS 8 and GS/OS applications to use these file type and
  324. auxiliary type assignments when creating AppleDouble files.
  325.  
  326. AppleDouble files which do not have file type $E0 and auxiliary type $0002 or
  327. $0003 can most easily be identified by opening them and attempting to interpret
  328. them.  If it is not an AppleDouble Header File, the Magic Number is not
  329. contained in the first four bytes of the file.  The chances that the file would
  330. begin with those four bytes and not be an AppleDouble Header File, on a purely
  331. random basis, are 4,294,967,295 to 1.  The chances that both the Magic Number
  332. and the Version bytes would be the same in a non-AppleSingle file are roughly
  333. 1.8 x 10^19 to 1.
  334.  
  335.  
  336. Finding the AppleDouble Data File
  337.  
  338. Since the AppleDouble Data File can be stored anywhere, with any file typeand
  339. auxiliary type, a program may have to make an effort to find it.  Werecommend
  340. the following steps:
  341.  
  342. 1.  If the Data Pathname segment exists, use that pathname.  If the
  343.     path specified in the segment does not exist, extract the file
  344.     name from the end of the pathname and look in the current
  345.     directory for that file name.
  346. 2.  If Step 1 does not find the file (or if the Data Pathname segment
  347.     does not exist), perform the appropriate Home File System
  348.     algorithm (described below) to generate the name of the
  349.     AppleDouble Data File from the AppleDouble Header File.
  350. 3.  If none of the file names generated in Step 2 are found, ask the
  351.     user where the AppleDouble Data File is located.
  352.  
  353.  
  354. Filename Conventions:
  355.  
  356. Apple proposes the following standard for identifying AppleDouble Header File
  357. names and AppleDouble Data File names from the file's real name.
  358.  
  359. ProDOS:
  360.  
  361. To generate the AppleDouble Data File name, use character substitution or
  362. deletion to remove illegal characters, and use truncation if necessary to
  363. reduce the length of the name to two characters less than the maximum file
  364. name length.  This would be a maximum of 13, since the maximum file name
  365. length is 15.
  366.  
  367. To generate the AppleDouble Header File name, prefix the AppleDouble DataFile
  368. name with the characters "R." (uppercase R period).
  369.  
  370. For example, the file name "This is a Foo File" could translate to an
  371. AppleDouble Data File Name of "THIS.IS.A.FOO."  The AppleDouble Header File
  372. name would then be "R.THIS.IS.A.FOO."
  373.  
  374. Unix:
  375.  
  376. To generate the AppleDouble Data File name, use character substitution to
  377. replace any illegal characters with an underscore (_).  Since different Unix
  378. systems have different requirements on maximum file name length, do not
  379. explicitly truncate the name to a specific length.  Rather, allow the
  380. truncation to be done by the Unix functions create(), open(), etc.
  381.  
  382. To generate the AppleDouble Header File name, A/UX (Apple's implementation of
  383. Unix for Macintosh computers) prefixes a percent sign (%) to the AppleDouble
  384. Data File name.  If necessary, truncate the last character to keep the file name
  385. within the legal length range.  Other Unix systems may prefix adirectory name
  386. (e.g., ".AppleDouble/") to the AppleDouble Data File name to create the name of
  387. the AppleDouble Header File.  In this scheme, all AppleDouble Header Files
  388. corresponding to AppleDouble Data files are kept together in a single
  389. subdirectory.
  390.  
  391. MS-DOS:
  392.  
  393. To generate the AppleDouble Data File name, use character substitution or
  394. deletion to remove illegal characters, and use truncation if necessary to
  395. reduce the length of the name to eight characters.  Then add the MS-DOS
  396. extension that is most appropriate to the file (such as "TXT" for a pure text
  397. file).
  398.  
  399. To generate the AppleDouble Header File name, add the extension ".ADF" to the
  400. eight-character file name.
  401.  
  402. In any instance, most programs probably wish to display the names being used
  403. for both AppleDouble files, so that the user may keep track of them on disk.
  404.  
  405. AppleDouble name derivations will be defined for all other file systems of
  406. interest.  This allows applications running on the foreign file system (and
  407. users as well) to see easily which files are AppleDouble pairs.Knowledgeable
  408. users, if they know the derivation, could rename or move the files so as to
  409. preserve the connection between the two.  However, there is no guaranteed way to
  410. prevent one file of the pair from being inconsistently renamed, moved, or
  411. deleted.
  412.  
  413.  
  414. About AppleDouble 2.0
  415.  
  416. AppleDouble 2.0 is a revision to the original AppleDouble specification
  417. described in this Note.  AppleDouble 2.0 comes closer to the ideal of an
  418. interchange format by allowing file information for multiple file systems in the
  419. same AppleDouble file.
  420.  
  421. AppleDouble 2.0 basically replaces the File Info entry (ID = 7) with a File
  422. Dates entry (ID = 8) and one or more host file system entries, such as a
  423. Macintosh File Info entry (ID = 10), a ProDOS File Info entry (ID = 11), or an
  424. MS-DOS File Info entry (ID = 12).  Information on these entries and AppleDouble
  425. 2.0 can be found in the AppleSingle/AppleDouble Formats for Foreign Files
  426. Developer's Note, available from APDA, AppleLink, and the Developer CD series.
  427.  
  428.  
  429. Further Reference
  430. _____________________________________________________________________________
  431.   o  Inside Macintosh, Volume IV
  432.   o  ProDOS 8 Technical Reference Manual
  433.   o  GS/OS Reference
  434.   o  AppleSingle/AppleDouble Formats for Foreign Files Developer's Note
  435.  
  436.  
  437.